package com.cljz.makepassenger.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import com.cljz.makepassenger.R;
import com.cljz.makepassenger.model.net.bean.GetTypeListBean;
import com.cljz.makepassenger.ui.holder.ModelAddHolder;

import java.util.List;

/**
 * Created by apple on 2017/4/26.
 */

public class ModelAddAdapter extends RecyclerView.Adapter<ModelAddHolder> {


    private List<GetTypeListBean.DataBean> typeList;
    private Context context;
    private OnItemClickListener mOnItemClickListener;

    public ModelAddAdapter(List<GetTypeListBean.DataBean> typeList, Context context) {
        this.typeList = typeList;
        this.context = context;
    }

    public List<GetTypeListBean.DataBean> getTypeList() {
        return typeList;
    }

    public void setTypeList(List<GetTypeListBean.DataBean> typeList) {
        this.typeList = typeList;
        notifyDataSetChanged();
    }

    public Context getContext() {
        return context;
    }

    public void setContext(Context context) {
        this.context = context;
    }


    @Override
    public ModelAddHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ModelAddHolder(View.inflate(context, R.layout.item_model_add, null));
    }

    @Override
    public void onBindViewHolder(ModelAddHolder holder, final int position) {
        holder.setData(typeList, position);
        if (mOnItemClickListener != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    mOnItemClickListener.onClick(typeList, position);
                }
            });

            holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    mOnItemClickListener.onLongClick(typeList, position);
                    return false;
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return typeList == null ? 0 : typeList.size();
    }

    public interface OnItemClickListener {
        void onClick(List<GetTypeListBean.DataBean> typeList, int position);

        void onLongClick(List<GetTypeListBean.DataBean> typeList, int position);
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }
}
